1. Field of the Invention
Aspects of the present invention relate to efficient management of stacks of an application for efficient memory acquisition for an operating system and, more particularly, to an apparatus and method that can ensure large capacity memory acquisition for an operating system by storing a stack region exceeding a predetermined range in a compressed format.
2. Description of the Related Art
Conventionally, securing memory has been carried out by retrieval of data in a read-only region, retrieval of a dirty page, or retrieval of an anonymous page using a swap space. The retrieval of the data in the read-only region uses the characteristics of the data in the read-only region. Since a code of an application to be executed is read-only, the code is not changed during the execution of the application. An image of an execution file can be temporarily erased from a memory because the image has already been stored. Thus, by retrieving the data in the read-only region, free space in the memory can be acquired efficiently.
The operating system does not immediately write a page in a file, change the page in the memory, and mark the page as a dirty (changed) page. Instead, when there is insufficient memory space, free space of the memory is acquired by writing the dirty page in a file and retrieving the dirty page.
The anonymous page indicates a page, such as a heap or a stack, that is not related to an image of a file and is dynamically generated during the execution of an application. If a space that can be swapped exists in a system, a free space of the memory can be acquired such that the anonymous page of the application swaps out, referred to as the retrieval of the anonymous page using the swap space.
FIG. 1 is a conceptual view illustrating memory allocation during the execution of an application according to the prior art. In general, once a specific function 101 of an application is compiled and is executed in assembly language, a predetermined stack 103 of a memory is allocated for the execution of the application according to assembly language. Similarly, upon execution of another function 102, a predetermined stack 104 is allocated according to interpreted assembly language. In this way, if an application is executed, only a portion of the entire region of the memory, instead of the entire region of the memory, is intensively used, which is called locality. Currently used embedded systems do not include a swap space and thus cannot use retrieval of an anonymous page, nor do currently used methods consider a usage pattern of a stack having strong locality.
FIGS. 2A and 2B are conceptual views illustrating stack usage of an application according to the prior art. In FIG. 2A, a first region 220 indicates currently used stack pages in a memory and a second region 230 indicates a stack page that has not yet been allocated. A current stack pointer 210 is positioned at a boundary between the first region 220 and the second region 230, i.e., between the last allocated stack page and a non-allocated stack page. Upon execution of an application, more stack pages are allocated as the number of functions to be processed increases, as illustrated in FIG. 2B.
In FIG. 2B, a first region 240 indicates currently used stack pages in a memory and a second region 250 indicates frequently referred stack pages. The current stack pointer 210 is positioned between the last allocated stack page and a non-allocated stack page. The first region 240 is used, but is not frequently referred to, unlike the second region 250. Thus, the memory space that is available to the operating system decreases due to the first region 240.